import 'package:aitao_flutter/mine/controller/say_hello_controller.dart';
import 'package:aitao_flutter/mine/views/say_hello_audio_page.dart';
import 'package:aitao_flutter/mine/views/say_hello_img_page.dart';
import 'package:aitao_flutter/mine/views/say_hello_text_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../model/hello_text_model.dart';
import '../../style/color_style.dart';
import '../../style/text_style.dart';

class SayHelloPage extends StatefulWidget {
  const SayHelloPage({Key? key}) : super(key: key);

  @override
  State<SayHelloPage> createState() => _SayHelloPageState();
}

class _SayHelloPageState extends State<SayHelloPage>
    with SingleTickerProviderStateMixin {
  final SayHelloController controller = Get.put(SayHelloController());
  late TabController tabController;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SayHelloController>(builder: ((controller) {
      return SafeArea(
          child: Scaffold(
        backgroundColor: ColorStyle.backGroundColor,
        body: Column(children: [
          Container(
            padding: const EdgeInsets.fromLTRB(14, 0, 14, 0),
            height: 44.h,
            color: ColorStyle.backGroundColor,
            child:
                Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
              GestureDetector(
                  child: Icon(
                    Icons.arrow_back_ios_new_outlined,
                    color: ColorStyle.normalTextColor,
                    size: 20.w,
                  ),
                  onTap: () {
                    Get.back();
                  }),
              Expanded(
                  child: Container(
                alignment: Alignment.center,
                color: ColorStyle.backGroundColor,
                child: TabBar(
                  onTap: (i) {
                    controller.tabIndex = i;
                  },
                  isScrollable: true,

                  labelColor: ColorStyle.normalTextColor,
                  indicatorColor: ColorStyle.themeColor,
                  indicatorSize: TabBarIndicatorSize.label,
                  indicatorPadding: const EdgeInsets.only(left: 8, right: 8),
                  indicatorWeight: 3,
                  labelPadding: const EdgeInsets.only(bottom: 5),
                  // labelStyle: Styles.boldText_16,
                  // unselectedLabelStyle: const TextStyle(
                  //     color: ColorStyle.ashGreyColor, fontSize: 15),
                  tabs: controller.tabList.asMap().entries.map((e) {
                    return Padding(
                        padding: const EdgeInsets.only(left: 8, right: 8),
                        child: Text(e.value,
                            style: e.key == controller.tabIndex
                                ? Styles.normalText_16
                                : const TextStyle(
                                    color: ColorStyle.normalTextColor,
                                    fontSize: 15)));
                  }).toList(),
                  controller: tabController,
                ),
              )),
              GestureDetector(
                child: Text(
                  '添加',
                  style: Styles.mainText_15,
                ),
                onTap: () {
                  controller.addClick();
                },
              )
            ]),
          ),
          Expanded(
              child: TabBarView(
            controller: tabController,
            children: [
              GetBuilder<SayHelloController>(
                  id: 'helloText',
                  builder: ((controller) {
                    return SayHelloTextPage(
                      textList: controller.textList,
                      deleteCallBack: (model) {
                        HelloTextModel m = model;
                        controller.deleteHelloText(m);
                      },
                    );
                  })),
              GetBuilder<SayHelloController>(
                  id: 'helloImage',
                  builder: ((controller) {
                    return SayHelloImagePage(
                      imageList: controller.imageList,
                    );
                  })),
              GetBuilder<SayHelloController>(
                  id: 'helloAudio',
                  builder: ((controller) {
                    return SayHelloAudioPage(
                      addHelloText: addHelloText,
                    );
                  })),
            ],
          ))
        ]),
      ));
    }));
  }

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this, initialIndex: 0);
  }

  void addHelloText() {
    debugPrint('addHelloText');
  }
}
